<?php
/**
 * Created by PhpStorm.
 * User: hooshim
 * Date: 2014-12-03
 * Time: 오전 11:23
 */

header("Content-Type:text/html;charset=utf-8");
header("Cache-Control:no-cache");
header("Pragma:no-cache");

include_once ($_SERVER['DOCUMENT_ROOT']."/inc/conn.inc.php");
include_once ($_SERVER['DOCUMENT_ROOT']."/inc/function.inc.php"); ##property 파일 인크루드됨.

	//## 파라미터 선언
    $expressCd 			= $_POST['expressCd'];
    $dcRate 			= $_POST['dcRate'];
    $oilRate 			= $_POST['oilRate'];
    //if (!$expressCd) $expressCd = 'EMS';

	// Table 이름 선언
	$tbname = "tblRateExpress";

    $curDt =date("Y-m-d");
    if ($dcRate != 0 && $dcRate !="")
    {
        $dcRate = $dcRate / 100;
        $minus01 = "-(A.zone01*{$dcRate})";
        $minus02 = "-(A.zone02*{$dcRate})";
        $minus03 = "-(A.zone03*{$dcRate})";
        $minus04 = "-(A.zone04*{$dcRate})";
        $minus05 = "-(A.zone05*{$dcRate})";
        $minus06 = "-(A.zone06*{$dcRate})";
        $minus07 = "-(A.zone07*{$dcRate})";
        $minus08 = "-(A.zone08*{$dcRate})";
        $minus09 = "-(A.zone09*{$dcRate})";
        $minus10 = "-(A.zone10*{$dcRate})";
    }

    if ($oilRate != 0 && $oilRate !="")
    {
        $oilRate = $oilRate / 100;
        $plus01 = "+(A.zone01*{$oilRate})";
        $plus02 = "+(A.zone02*{$oilRate})";
        $plus03 = "+(A.zone03*{$oilRate})";
        $plus04 = "+(A.zone04*{$oilRate})";
        $plus05 = "+(A.zone05*{$oilRate})";
        $plus06 = "+(A.zone06*{$oilRate})";
        $plus07 = "+(A.zone07*{$oilRate})";
        $plus08 = "+(A.zone08*{$oilRate})";
        $plus09 = "+(A.zone09*{$oilRate})";
        $plus10 = "+(A.zone10*{$oilRate})";
    }
    $query = "SELECT A.expressCd, CASE WHEN A.expressClass='N' THEN '보통' ELSE '고급' END as class, A.cargoType, A.weight";
    $query .= ", REPLACE(CONVERT(varchar, CAST((A.zone01{$plus01}{$minus01}) AS money), 1), '.00', '') zone01, REPLACE(CONVERT(varchar, CAST((A.zone02{$plus02}{$minus02}) AS money), 1), '.00', '') zone02 ";    
    $query .= ", REPLACE(CONVERT(varchar, CAST((A.zone03{$plus03}{$minus03}) AS money), 1), '.00', '') zone03, REPLACE(CONVERT(varchar, CAST((A.zone04{$plus04}{$minus04}) AS money), 1), '.00', '') zone04 ";
    $query .= ", REPLACE(CONVERT(varchar, CAST((A.zone05{$plus05}{$minus05}) AS money), 1), '.00', '') zone05, REPLACE(CONVERT(varchar, CAST((A.zone06{$plus06}{$minus06}) AS money), 1), '.00', '') zone06 ";
    $query .= ", REPLACE(CONVERT(varchar, CAST((A.zone07{$plus07}{$minus07}) AS money), 1), '.00', '') zone07, REPLACE(CONVERT(varchar, CAST((A.zone08{$plus08}{$minus08}) AS money), 1), '.00', '') zone08 ";
    $query .= ", REPLACE(CONVERT(varchar, CAST((A.zone09{$plus09}{$minus09}) AS money), 1), '.00', '') zone09, REPLACE(CONVERT(varchar, CAST((A.zone10{$plus10}{$minus10}) AS money), 1), '.00', '') zone10";
    $query .= " FROM {$tbname} A LEFT JOIN (SELECT itemCd, itemSeq FROM tblComCode WHERE groupCd='0002' AND flag='Y') B ON A.cargoType=B.itemCd ";
    $query .= " WHERE A.flag='Y' AND A.expressCd='{$expressCd}' AND A.dateToApply<='{$curDt}' ORDER BY A.expressClass, B.itemSeq, A.weight";
    $logger->debug($query ."<br>[#FROM:" . $G_remote_ip."#]"); ## 쿼리 로그 작성
    $result = makeJSONArray($query,"GRIDDATA");

    $output = json_encode($result);
    $output = urldecode($output);
    echo $output;
   // echo iconvDecode($output);
    $logger->debug($_SESSION['BID'] ."//" .$output ."<br>[#FROM:" . $G_remote_ip."#]"); ## 결과 로그 작성
?>